package Tests;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import ModelLayer.ContractorRecords;
import ModelLayer.RealException;

public class ContractorTest {

	private ContractorRecords contractorRecords = ContractorRecords.getInstance();
	

	@Before
	public void setUp() throws Exception {
		contractorRecords.addContractor("Madalin", "Hobrovej", 555);
	}

	@Test
	public void testUpdateName() throws RealException {
		contractorRecords.getContractor(1).setName("Test");
		Assert.assertEquals("Test", contractorRecords.getContractor(1).getName());
	}
	
	@Test
	public void testUpdateAddress() throws RealException {
		contractorRecords.getContractor(1).setAddress("Test");
		Assert.assertEquals("Test", contractorRecords.getContractor(1).getAddress());
	}
	
	@Test
	public void testUpdatePhone() throws RealException {
		contractorRecords.getContractor(1).setPhone(777);
		Assert.assertEquals(777, contractorRecords.getContractor(1).getPhone());
	}

	
	@Test
	public void testDelete() throws RealException {
		contractorRecords.removeContractor(1);
		boolean found = true;
		try
		{
			contractorRecords.getContractor(1);
		}
		catch (RealException e) 
		{
			found = false;
		}
		Assert.assertFalse(found);		
	}
	
	@Test
	public void testGet() throws RealException {
		Assert.assertNotSame(null, contractorRecords.getContractor(1));
	}
}
